OpenRoads Designer CONNECT Edition SDK Help

Report used element templates in DGN or DGNlib

The below code shows how to get all used element templates from current file.


//Required References
using System.Collections.Generic;
using Bentley.CifNET.Model;
using System.Diagnostics;

  public List<string> AllUsedElementTemplates()
        {
            List<string> allUsedElementTemplates = new List<string>();

            //Get object space
            Bentley.CifNET.CadSystem.IObjectSpaceManager objectSpaceManager = Bentley.CifNET.ServiceManager.Instance.GetService<Bentley.CifNET.CadSystem.IObjectSpaceManager>();
            if (objectSpaceManager == null) return null;
            Bentley.CifNET.Objects.IObjectSpace objectSpace = objectSpaceManager.ObjectSpace;
            if (objectSpace == null) return null;

            Trace.WriteLine("All Used templates from current file: ");
            //Get all used element templates
            foreach (Bentley.CifNET.Model.ElementTemplate template in objectSpace.GetCachedObjectSet(typeof(ElementTemplate)))
            {
                allUsedElementTemplates.Add(template.Path);
                Trace.WriteLine("Template Name =" + template.Path);
            }
            return allUsedElementTemplates;
        }

Output